package org.gdkm.springbootxiangmushizhan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.gdkm.springbootxiangmushizhan.domain.vo.UserAdminVO;
import org.gdkm.springbootxiangmushizhan.mapper.UserMapper;
import org.gdkm.springbootxiangmushizhan.service.IUserService;
import org.gdkm.springbootxiangmushizhan.domain.po.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo<UserAdminVO> getAllUsersWithPage(int page, int count) {
        PageHelper.startPage(page, count);
        List<UserAdminVO> list = userMapper.selectAllUsersWithPage();
        return new PageInfo<>(list);
    }

    @Override
    public void deleteUserById(Integer id) {
        userMapper.deleteUserById(id);
    }

    @Override
    public void updateUserValidById(Integer id, Integer valid) {
        userMapper.updateUserValidById(id, valid);
    }

    @Override
    public User selectUserById(Integer id) {
        return userMapper.selectUserById(id);
    }

    @Override
    public void updateUserById(User user) {
        userMapper.updateUserById(user);
    }

    @Override
    public void insertUser(User user) {
        userMapper.insertUser(user);
    }

    @Override
    public void insertUserAuthority(Integer userId, Integer authorityId) {
        userMapper.insertUserAuthority(userId, authorityId);
    }
} 